/*
 * OverviewListActivity.java
 *
 * Copyright(c) 2011
 * Michael Kroez
 * kroez@studiorutton.de
 *
 * All rights reserved.
 *
 * $Id$
 * 
 */

package de.studiorutton.gerengdic.overview;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import de.studiorutton.colorschemes.IColorSchemeMapper;
import de.studiorutton.gerengdic.Prefs;
import de.studiorutton.gerengdic.R;

public class OverviewListActivity extends ListActivity implements
		IOverviewListener {
	private final static String TAG = "learningwords";

	private Overview o;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "OverviewListActivity: starting onCreate");
		
	}

	public void onStart() {
		super.onStart();
		// Log.d(TAG, "OverviewListActivity: starting onResume");
		o = Overview.get( this );
		setContentView(R.layout.overview);

		IColorSchemeMapper csmi = Prefs.getInstance().getColorSchemeMapper();

		// RelativeLayout rl = (RelativeLayout) findViewById( R.id.title );
		// rl.setBackgroundResource( cscheme.getBackgroundLightSmall() );
		// TextView title = (TextView) findViewById( R.id.downloadtitle );
		// title.setTextColor( cscheme.getTextColorDark());
	}

	public void onResume() {
		super.onResume();
		Log.d(TAG, "OverviewListActivity: starting onResume");
		o.setOverviewListener(this);
		setListAdapter(o.getOverviewAdapter());

		executeOverview();

	}

	public void onPause() {
		super.onPause();

		if (isFinishing()) {
			Overview.release();
			o = null;
		}
	}

	private boolean executeOverview() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			String text = extras.getString(Overview.bundle_package + "."
					+ Overview.TEXT);
			Log.d(TAG, "executeOverview: text = " + text);
			o.parseItem(text);
			return true;
		}
		return false;
	}

	public Context getContext() {
		return this;
	}

	public void notifyError(String msg) {
		CharSequence text = "Cannot play voice. Sorry.";
		int duration = Toast.LENGTH_SHORT;

		Toast toast = Toast.makeText(this, text, duration);
		toast.show();
	}

}
